// 标准输入输出
// process.stdin.pipe(process.stdout)

// const http = require('http')
// const server = http.createServer((req, res) => {
//     if (req.method === 'POST') {
//         req.pipe(res) // 最主要
//     }
// })

// server.listen(8000)

// // 复制文件
// const fs = require('fs')
// const path = require('path')

// const tobeCopyedFile = path.resolve(__dirname, 'data.txt')
// const CopyedFile = path.resolve(__dirname, 'data-bak.txt')

// // 分别新建两个输入输出流
// const readStream = fs.createReadStream(tobeCopyedFile)
// const writeStream = fs.createWriteStream(CopyedFile)

// // 然后倒水
// readStream.pipe(writeStream)

// // 监听每一次读取的数据
// readStream.on('data', (chunk)=> {
//     console.log(chunk.toString());
// })

// // 处理拷贝完成
// readStream.on('end', () => {
//     console.log('copy success');
// })

// 结合文件 IO 操作 http 操作
const fs = require('fs')
const path = require('path')

const http = require('http')
const tobeCopyedFile = path.resolve(__dirname, 'data.txt')
const server = http.createServer((req, res) => {
    if (req.method === 'GET') {
        const readStream = fs.createReadStream(tobeCopyedFile)
        readStream.pipe(res)
    }
})

server.listen(8000)